import { defineStore } from 'pinia';

interface GameState {
  drawingDataUrl: string | null;
  aiGuess: string | null;
  gamePhase: 'idle' | 'drawing' | 'guessing' | 'result';
  isLoading: boolean;
  error: string | null;
}

export const useGameStore = defineStore('game', {
  state: (): GameState => ({
    drawingDataUrl: null,
    aiGuess: null,
    gamePhase: 'idle', // 初始状态
    isLoading: false,
    error: null,
  }),
  actions: {
    setDrawingData(dataUrl: string) {
      this.drawingDataUrl = dataUrl;
    },
    startGuessing() {
        if (!this.drawingDataUrl) {
            this.error = '没有绘图数据可供猜测';
            return;
        }
        this.gamePhase = 'guessing';
        this.isLoading = true;
        this.aiGuess = null;
        this.error = null;
        // 此处稍后将触发 API 调用
    },
    setGuessResult(guess: string) {
      this.aiGuess = guess;
      this.gamePhase = 'result';
      this.isLoading = false;
    },
    setError(errorMessage: string) {
      this.error = errorMessage;
      this.isLoading = false;
      this.gamePhase = 'idle'; // 或者保持在某个错误状态?
    },
    resetGame() {
      this.drawingDataUrl = null;
      this.aiGuess = null;
      this.gamePhase = 'idle';
      this.isLoading = false;
      this.error = null;
    },
    setPhase(phase: GameState['gamePhase']) {
      this.gamePhase = phase;
    }
  },
}); 